<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
/*Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});*/

Route::group(['namespace' => 'Api'], function ($router) {
    $router->post('/login', 'UserController@login');
    $router->get('deportment/all','DeportmentController@all');
    $router->get('deportment','DeportmentController@index');
    $router->get('patient-type', 'PatientTypeController@index');
    $router->get('doctor','DoctorController@index');
    $router->get('media','MediaController@index');
    $router->get('role', 'RoleController@index');
    $router->get('user/role/{user_id}', 'RoleUserController@show');
});
Route::group(['namespace' => 'Api', 'middleware' => 'auth:api'],function ($router){
    $router->get('user/{id}', 'UserController@show');
    $router::group(['middleware' => 'permission:user'],function ($router) {
        $router->post('/register', 'UserController@create');
        $router->get('user/role/bind/{id}/{role_id}', 'UserController@userBindRole');
        $router->get('user/role/remove/{id}/{role_id}', 'UserController@userRemoveRole');
        $router->get('user/role/remove-all/{id}', 'UserController@userRemoveAllRole');
        $router->get('user/permission/bind/{id}/{permission_id}', 'UserController@userBindPermission');
        $router->get('user/permission/remove/{id}/{permission_id}', 'UserController@userRemovePermission');
        $router->get('user/permission/remove-all/{id}', 'UserController@userRemoveAllPermission');
        $router->get('user/permission/{user_id}', 'PermissionUserController@show');
        $router->get('user', 'UserController@all');
        $router->post('user/{id}/update', 'UserController@update');
        $router->delete('user/{id}', 'UserController@destroy');
    });
    $router::group(['middleware' => 'permission:patienttype'],function ($router) {
        //patient-type
        $router->resource('patient-type', 'PatientTypeController', array('except' => array('index','create','edit')));
    });
    //deportment
    $router::group(['middleware' => 'permission:deportment'],function ($router) {
    $router->resource('deportment','DeportmentController', array('except' => array('index','create','edit')));
    });
    $router::group(['middleware' => 'permission:doctor'],function ($router) {
    //doctor
    $router->resource('doctor','DoctorController', array('except' => array('index','create','edit')));
    });
    $router::group(['middleware' => 'permission:media'],function ($router) {
    //media
    $router->resource('media','MediaController', array('except' => array('index','create','edit')));
    });
    /*Route::group(['middleware' => 'zone'],function ($router) {
    //zone
    $router->resource('zone','ZoneController');
    });*/
    //patient
    $router->get('patient/user','PatientController@showByUser')->middleware('permission:patient.all.user');
    $router->get('patient/doctor','PatientController@showByDoctor')->middleware('permission:patient.all.doctor');
    $router->get('patient/deportment','PatientController@showByDeportment')->middleware('permission:patient.all.deportment');
    $router->get('patient','PatientController@index')->middleware('permission:patient.all');
    $router->post('patient','PatientController@store')->middleware('permission:patient.store');
    $router->get('patient/{id}','PatientController@show')->middleware('permission:patient.show');
    $router->put('patient/{id}','PatientController@update')->middleware('permission:patient.update');
    $router->delete('patient/{id}','PatientController@destroy')->middleware('permission:patient.delete');
    //$router->resource('patient','PatientController');
    $router::group(['middleware' => 'permission:role'],function ($router) {
        //role
        $router->get('role/permission/{role_id}', 'PermissionRoleController@show');
        $router->get('role/action/bind/{id}/{permission_id}', 'RoleController@roleBindPermission');
        $router->get('role/action/remove/{id}/{permission_id}', 'RoleController@roleRemovePermission');
        $router->get('role/action/remove-all/{id}', 'RoleController@roleRemoveAllPermission');
        $router->resource('role', 'RoleController', array('except' => array('index','create','edit')));
    });
    $router::group(['middleware' => 'permission:permission'],function ($router) {
    //permission
    $router->resource('permission','PermissionController');
    });
});
